<template>
  <t-table
    row-key="id"
    table-layout="auto"
    height="60vh"
    :data="outboundStore.getList()"
    :columns="columns"
    :pagination="outboundStore.page"
    :loading="outboundStore.page.loading"
    @page-change="({ current, pageSize }) => outboundStore.reset(current, pageSize)"
    hover
  >
    <template #code="{ row }">
      <t-tag theme="primary" variant="light">{{ row.code }}</t-tag>
    </template>
    <template #name="{ row }">
      <b>{{ row.name }}</b>
    </template>
    <template #count="{ row }">
      {{ row.count }}
    </template>
    <template #time="{ row }">
      {{ row.created_at.date() }}
    </template>
    <template #right="{ row }">
      <t-dropdown :min-column-width="88" trigger="click" @click="item => emit(item.value, row)">
        <t-button theme="primary" variant="text">
          {{ $t('common.active') }} 
          <template #suffix><t-icon name="chevron-down" size="14" /></template>
        </t-button>
        <template #dropdown>
          <t-dropdown-menu>
            <t-dropdown-item value="info">{{ $t('common.info') }}</t-dropdown-item>
          </t-dropdown-menu>
        </template>
      </t-dropdown>
    </template>
  </t-table>
</template>
<script setup>
  import { ref } from 'vue'
  import app from '@/app'
  import index from '../../index'
  import outboundStore from '../../store/outbound'

  const emit = defineEmits(['info'])
  const plugin = index.plugin
  const columns = [{
    title: plugin.t('outbound.account_name'),
    colKey: 'account_name'
  }, {
    title: plugin.t('outbound.client_name'),
    colKey: 'client_name'
  }, {
    title: plugin.t('outbound.code'),
    colKey: 'code',
    cell: 'code'
  }, {
    title: plugin.t('outbound.name'),
    colKey: 'name',
    cell: 'name'
  }, {
    title: plugin.t('outbound.count'),
    colKey: 'count',
    cell: 'count',
    align: 'center'
  }, {
    title: plugin.t('inbound.time'),
    colKey: 'time',
    cell: 'time'
  }, {
    colKey: 'right',
    align: 'right',
    cell: 'right',
    fixed: 'right'
  }]

  outboundStore.get()
</script>